package com.jt.common.util;

import com.jt.common.exception.RestException;
import com.jt.common.response.Response;
import com.jt.common.response.ResponseCode;


public class ResponseUtil {

    public static <T> T formatResponse(Response<T> response) {
        if (null != response && response.getCode() == ResponseCode.SUCCESS.getCode() && null != response.getResult()) {
            return (T) response.getResult();
        } else {
            if (response == null) {
                throw new RestException(ResponseCode.CALL_FAILS);
            } else {
                throw new RestException(response.getCode(), response.getMessage());
            }
        }
    }
}
